<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org"  xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<meta charset="utf-8">
<head th:include="centre/manage/include :: header">
</head>

<link rel="stylesheet" type="text/css" href="/css/plugins/layui/layui.css"/>
<link href="/css/jquery-select/jquery.searchableSelect.css" rel="stylesheet" type="text/css">
<style>
    .province {
        float: left;
        position: relative;
        width: 150px;
        height: 35px;
        line-height: 35px;
        border: 1px solid #fff;
    }

    .province:hover {
        border: 1px solid #f7e4a5;
        border-bottom: 1px solid #fffec6;
        background: #fffec6;
    }

    .province .cityall {
        margin-top: 10px;
    }

    .province ul {
        list-style: outside none none;
        position: absolute;
        padding: 0;
        background: #fffec6;
        border: 1px solid #f7e4a5;
        display: none;
        width: auto;
        width: 300px;
        z-index: 999999;
        left: -26px;
        top: 33px;
    }

    .province ul li {
        float: left;
        min-width: 60px;
        margin-left: 20px;
        height: 30px;
        line-height: 30px;
    }

    .province .checkbox-inline {
        padding-top: 0;
    }

    h3, h4, h5 {
        margin: 5px 0;
        font-weight: 600;
    }

    input[type=email], input[type=url], input[type=search], input[type=tel],
    input[type=color], input[type=text], input[type=password], input[type=datetime],
    input[type=datetime-local], input[type=date], input[type=month], input[type=time],
    input[type=week], input[type=number], textarea {
        border-radius: 0 !important;
        color: #858585;
        background-color: #FFF;
        border: 1px solid #D5D5D5;
        padding: 5px 4px 6px;
        font-size: 14px;
        font-family: inherit;
        -webkit-box-shadow: none !important;
        box-shadow: none !important;
        -webkit-transition-duration: .1s;
        transition-duration: .1s;
    }

    .spectable td, .spectable th {
        border: 1px solid #ccc;
        vertical-align: middle;
        text-align: center;
    }

    .spectable th {
        font-weight: bold;
    }

    .spectableinput {
        text-align: center;
    }

    .f {
        border-color: #b94a48;
        -webkit-box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075);
        -moz-box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075);
        box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075);
    }

    .table.table-bordered tr th, .table.table-bordered tr td {
        overflow: hidden;
        text-overflow: ellipsis;
    }

    select {
        padding: 3px 4px;
        height: 30px;
    }

    .form-group .goods-thumb {
        float: left;
        margin-right: 10px;
        width: 50px;
        height: 50px;
        background-position: 50%;
        background-size: cover;
    }

    .form-group .goods-control {
        width: 400px;
        margin: 10px;
    }

    .form-group .goods-actions {
        float: right;
        margin-right: 20px;
    }

</style>
<body class="gray-bg">
<div class="wrapper wrapper-content">
    <div class="row">
        <div class="col-sm-12">
            <!--			<form class="form-horizontal m-t" id="signupForm">-->
            <input type="hidden" id="activityId" name="activityId" th:value="${activityId}">
            <input type="hidden" id="centreId" name="centreId" th:value="${activity.centreId}">
            <input type="hidden" id="teamId" name="teamId" th:value="${activity.teamId}">
            <div class="form-horizontal m-t">

                <div class="form-group">
                    <ul class="nav nav-arrow-next nav-tabs" id="myTab">
                        <li class="active"><a href="#tab_basic">活动设置</a></li>
                        <li><a href="#tab_des2">礼包详情</a></li>
                        <li><a href="#tab_des3">购买须知</a></li>
                        <li><a href="#tab_des4">商品说明</a></li>
                        <li><a href="#tab_des">活动店铺设置</a></li>
                    </ul>
                </div>

                <div class="tab-content" style="border: 0px;">

                    <div class="tab-pane active" id="tab_basic">
                        <div class="form-group">
                            <label class="col-sm-2 control-label">活动名称:</label>
                            <div class="col-sm-6">
                                <input id="activityName" name="activityName" placeholder="必填：活动名称"
                                       class="form-control" type="text" maxlength="100"
                                       th:value="${activity.activityName}">
                            </div>
                            <label class="col-sm-2 control-label"
                                   style="text-align: left;color:red;">*活动名称(50个汉字以内)</label>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">开始时间:</label>
                            <div class="col-sm-6">
                                <input type="text" class=" form-control"
                                       id="startTime" name="startTime" placeholder="开始时间"
                                       onclick="laydate({istime: true, format: 'YYYY-MM-DD hh:mm:ss'})"
                                       style="background-color: #fff;"
                                       th:value="${#dates.format(activity.startTime, 'yyyy-MM-dd HH:mm:ss')}"/>
                            </div>
                            <label class="col-sm-2 control-label" style="text-align: left;color:red;">*开始时间</label>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">结束时间:</label>
                            <div class="col-sm-6">
                                <input type="text" class=" form-control"
                                       id="endTime" name="endTime" placeholder="结束时间"
                                       onclick="laydate({istime: true, format: 'YYYY-MM-DD hh:mm:ss'})"
                                       style="background-color: #fff;"
                                       th:value="${#dates.format(activity.endTime, 'yyyy-MM-dd HH:mm:ss')}"/>
                            </div>
                            <label class="col-sm-2 control-label" style="text-align: left;color:red;">*结束时间</label>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-2 control-label">可售数量*:</label>
                            <div class="col-sm-4">
                                <input type="number" class=" form-control" id="stock" name="stock"
                                       th:value="${activity.stock}"
                                       style="background-color: #fff;"/>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">已售数量:</label>
                            <div class="col-sm-4">
                                <input type="number" class=" form-control" id="sold" name="sold"
                                       th:value="${activity.sold}"
                                       style="background-color: #fff;"/>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">套装限购*:</label>
                            <div class="col-sm-4">
                                <input type="text" class=" form-control" id="joinNum" name="joinNum"
                                       th:value="${activity.joinNum}"
                                       style="background-color: #fff;"/>
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-2 control-label">原价:</label>
                            <div class="col-sm-4">
                                <input type="text" class=" form-control" id="productprice" name="productprice"
                                       style="background-color: #fff;" th:value="${activity.productprice}"/>
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-2 control-label">活动价格*:</label>
                            <div class="col-sm-4">
                                <input type="text" class=" form-control" id="activityPrice" name="activityPrice"
                                       th:value="${activity.activityPrice}"
                                       style="background-color: #fff;"/>
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-2 control-label">vip价格:</label>
                            <div class="col-sm-4">
                                <input type="text" class=" form-control" id="vipPrice" name="vipPrice"
                                       style="background-color: #fff;" th:value="${activity.vipPrice}"/>
                            </div>
                        </div>


                        <div class="form-group">
                            <label class="col-sm-2 control-label">消耗积分:</label>
                            <div class="col-sm-4">
                                <input type="number" min="0" class=" form-control" id="consumptionIntegral" name="consumptionIntegral"
                                       style="background-color: #fff;" th:value="${activity.consumptionIntegral}"/>
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-2 control-label no-padding-right"
                                   for="form-field-1"> 活动图片*： </label>
                            <div class="col-sm-10">
                                <div class="col-sm-6">
                                    <div class="input-group ">
                                        <input type="text" name="thumb" id="thumb" value="" class="form-control"
                                               autocomplete="off" th:value="${activity.thumb}">
                                        <span class="input-group-btn">
												<button class="btn btn-sm btn-default" type="button"
                                                        style="padding:7px 10px"
                                                        onclick="onSelectImgBtnClick('thumb','thumbImg');">选择图片</button>
											</span>
                                    </div>
                                    <div class="input-group " style="margin-top: .5em;">
                                        <img src="" id="thumbImg" style="max-width: 30%" th:src="${activity.thumb}"/>
                                    </div>
                                </div>
                                <span class="lbl col-xs-12 col-sm-6"><span
                                        class="red"></span>此图片为商品列表图。</span>
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-2 control-label no-padding-right"
                                   for="form-field-1"> 列表图片*： </label>
                            <div class="col-sm-10">
                                <div class="col-sm-6">
                                    <div class="input-group ">
                                        <input type="text" name="listImg" id="listImg" value="" class="form-control"
                                               autocomplete="off" th:value="${activity.listImg}">
                                        <span class="input-group-btn">
												<button class="btn btn-sm btn-default" type="button"
                                                        style="padding:7px 10px"
                                                        onclick="onSelectImgBtnClick('listImg','listImgImg');">选择图片</button>
											</span>
                                    </div>
                                    <div class="input-group " style="margin-top: .5em;">
                                        <img src="" id="listImgImg" style="max-width: 30%" th:src="${activity.listImg}"/>
                                    </div>
                                </div>
                                <span class="lbl col-xs-12 col-sm-6"><span
                                        class="red"></span>此图片为商品列表图(228x150)</span>
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-2 control-label no-padding-right"
                                   for="form-field-1"> 海报图片*： </label>
                            <div class="col-sm-10">
                                <div class="col-sm-6">
                                    <div class="input-group ">
                                        <input type="text" name="posterImg" id="posterImg" value="" class="form-control"
                                               autocomplete="off" th:value="${activity.posterImg}">
                                        <span class="input-group-btn">
												<button class="btn btn-sm btn-default" type="button"
                                                        style="padding:7px 10px"
                                                        onclick="onSelectImgBtnClick('posterImg','posterImgImg');">选择图片</button>
											</span>
                                    </div>
                                    <div class="input-group " style="margin-top: .5em;">
                                        <img src="" id="posterImgImg" style="max-width: 30%" th:src="${activity.posterImg}"/>
                                    </div>
                                </div>
                                <span class="lbl col-xs-12 col-sm-6"><span
                                        class="red"></span>海报图片(300x360)</span>
                            </div>
                        </div>


                        <div class="form-group">
                            <label class="col-sm-2 control-label no-padding-right"
                                   for="form-field-1"> 详情图片*： </label>
                            <div class="col-sm-10">
                                <div class="col-sm-6">
                                    <div class="input-group ">
                                        <input autocomplete="off" class="form-control" id="detailsImg" name="detailsImg"
                                               placeholder="批量上传图片" th:value="${activity.detailsImg}" type="text"
                                               value="">
                                        <span class="input-group-btn">
<!--												<button class="btn btn-sm btn-default" type="button" style="padding:7px 10px" onclick="onSelectImgBtnClick('detailsImg','detailsImgImg');">选择图片</button>-->
                                            <button class="btn btn-sm btn-default" onclick="selectImgs('detailsImg');"
                                                    style="padding:7px 10px" type="button">选择图片</button>
											</span>
                                    </div>
                                    <div class="input-group " style="margin-top: .5em;">
                                        <img id="detailsImg" src="" style="max-width: 30%"
                                             th:src="${activity.detailsImg}"/>
                                    </div>
                                </div>
                                <span class="lbl col-xs-12 col-sm-6"><span
                                        class="red"></span>详情图片(375x250)</span>
                            </div>
                        </div>

                        <!--                        <div class="form-group">-->
                        <!--                            <label class="col-sm-2 control-label no-padding-right"-->
                        <!--                                   for="form-field-1">其他图片:</label>-->
                        <!--                            <div class="col-sm-10">-->
                        <!--                                <div class="col-sm-6">-->
                        <!--                                    <div class="input-group ">-->
                        <!--                                        <input type="text" name="thumbUrl" id="thumbUrl" th:value="${product.thumbUrl}" class="form-control" autocomplete="off" placeholder="批量上传图片">-->
                        <!--                                        <span class="input-group-btn">-->
                        <!--												<button class="btn btn-sm btn-default btn-file" style="padding:7px 10px" type="button" onclick="selectImgs('thumbUrl');">选择图片</button>-->
                        <!--											</span>-->
                        <!--                                    </div>-->
                        <!--                                    <div class="input-group " style="margin-top: .5em;">-->
                        <!--                                        <img src="" id="thumbUrl"/>-->
                        <!--                                    </div>-->
                        <!--                                </div>-->
                        <!--                                <span class="lbl col-xs-12 col-sm-6"><span-->
                        <!--                                        class="red"></span>如不上传此图默认其他图片第一张图片作为正方形图片</span>-->
                        <!--                            </div>-->
                        <!--                        </div>-->


                        <div class="form-group">
                            <label class="col-sm-2 control-label">版块类型:</label>
                            <div class="col-sm-8">
                                <label class="radio-inline"><label class="radio-inline">
                                    <input type="radio" name="plateType" value="0" th:field="*{activity.plateType}"/>普通版块
                                </label>
                                    <label class="radio-inline"><label class="radio-inline">
                                        <input type="radio" name="plateType" value="1" th:field="*{activity.plateType}"/>粤德公寓版块
                                    </label>
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-2 control-label">一级推荐人分佣:</label>
                            <div class="col-sm-6">
                                <input type="number" class=" form-control"
                                       id="giftBagCommission1" name="giftBagCommission1" placeholder="一级推荐人分佣" th:value="${activity.giftBagCommission1}"/>
                            </div>
                            <div class="col-sm-2">
                                <em>%</em> <span style="text-align: left;color:red;" id ="giftBagCommission1Num"></span>
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-2 control-label">二级推荐人分佣:</label>
                            <div class="col-sm-6">
                                <input type="number" class=" form-control"
                                       id="giftBagCommission2" name="giftBagCommission2" placeholder="二级推荐人分佣" th:value="${activity.giftBagCommission2}"/>
                            </div>
                            <div class="col-sm-2">
                                <em>%</em> <span style="text-align: left;color:red;" id ="giftBagCommission2Num"></span>
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-2 control-label">礼包分享佣金:</label>
                            <div class="col-sm-6">
                                <input type="number" class=" form-control"
                                       id="shareCommission" name="shareCommission" placeholder="礼包分享佣金" th:value="${activity.shareCommission}"/>
                            </div>
                            <div class="col-sm-2">
                                <em>%</em>
                            </div>
                        </div>

                        <div class="form-group text-center">
                            <div class="col-sm-8 col-sm-offset-2">
                                <!--														<button type="submit" class="btn btn-primary"><i class="fa fa-check"></i>提交</button>-->
                                <button class="btn btn-primary" onclick="saveActivity()">
                                    <i class="fa fa-check"></i>保存活动
                                </button>
                                <button class="btn btn-primary" onclick="nextStep()">
                                    <i class="fa fa-check"></i>下一步
                                </button>
                                <button class="btn btn-primary" onclick="closeDow()">
                                    <i class="fa fa-check"></i>关闭
                                </button>
                                <!--														<div class="btn btn-danger" onclick="reset()">-->
                                <!--															<i class="fa fa-remove"></i> 重置-->
                                <!--														</div>-->
                            </div>
                        </div>
                    </div>

                    <!-- 商品描述部分 开始 -->
                    <div class="tab-pane" id="tab_des2" style="height: 550px;">
                        <div class="form-group">
                            <label class="col-sm-2 control-label no-padding-right"
                                   for="form-field-1">礼包详情</label>
                            <div class="col-sm-10">
                                <textarea id="content" name="content" style="height: 500px;"
                                          th:text="${activity.description}"></textarea>
                            </div>
                        </div>
                    </div>

                    <!-- 购买须知部分 开始 -->
                    <div class="tab-pane" id="tab_des3" style="height: 550px;">
                        <div class="form-group">
                            <label class="col-sm-2 control-label no-padding-right">购买需知</label>
                            <div class="col-sm-10">
									<textarea id="tips" name="tips"
                                              style="height: 500px;" th:text="${activity.tips}"></textarea>
                            </div>
                        </div>
                    </div>

                    <!-- 商品说明部分 开始 -->
                    <div class="tab-pane" id="tab_des4" style="height: 550px;">
                        <div class="form-group">
                            <label class="col-sm-2 control-label no-padding-right">购买需知</label>
                            <div class="col-sm-10">
									<textarea id="productDescription" name="productDescription"
                                              style="height: 500px;"
                                              th:text="${activity.productDescription}"></textarea>
                            </div>
                        </div>
                    </div>

                    <!-- 活动店铺选择开始 -->
                    <div class="tab-pane" id="tab_des">
                        &nbsp;

                        <div class="form-group" id="choseGoodsGroup">
                            <!--<div class="col-md-4">选择赠送的商品</div>-->
                            <div class="col-md-4 col-xs-6" id="choseGoods">
                                <a class="click-font-color" onclick="chooseShop()">点击添加活动店铺</a>
                            </div>
                            <table id="joinProductListTable" data-mobile-responsive="true"></table>
                            <table style="margin-top: 20px;" id="activityProductTable" data-mobile-responsive="true"></table>
                            <table style="margin-top: 20px;" id="activityProductCouponTable" data-mobile-responsive="true"></table>
                        </div>

                        <div class="form-group text-center">
                            <div class="col-sm-8 col-sm-offset-2">
                                <button class="btn btn-primary" onclick="closeDow()">
                                    <i class="fa fa-check"></i>关闭
                                </button>
                            </div>
                        </div>
                    </div>
                </div>

                <div id="goodsSeckillPrice" style="display:none;    margin-top: 1rem;">
                    <div>
                        <label class="col-sm-4">活动价格:</label>
                        <div class="col-sm-8">
                            <input id="seckillPrice" name="displayorder" placeholder="必填：活动价格"
                                   class="form-control" type="number" value="0">
                        </div>
                    </div>
                    <div>
                        <label class="col-sm-4">活动库存:</label>
                        <div class="col-sm-8">
                            <input type="number"
                                   id="seckillStotal" name="seckillStotal" placeholder="必填:活动库存"/>
                        </div>
                    </div>
                </div>

                <div id="goodsPackageSetting" style="display:none;    margin-top: 1rem;">
                    <div>
                        <label class="col-sm-4">商品名称:</label>
                        <div class="col-sm-8">
                            <input id="goodsName" name="goodsName" placeholder="必填：商品名称"
                                   class="form-control" value="">
                        </div>
                    </div>
                    <div>
                        <label class="col-sm-4">商品库存:</label>
                        <div class="col-sm-8">
                            <input type="number" id="goodsStock" name="goodsStock" placeholder="必填:商品库存"/>
                        </div>
                    </div>
                    <div>
                        <label class="col-sm-4">套装价格:</label>
                        <div class="col-sm-8">
                            <input type="number"
                                   id="packagePrice" name="packagePrice" placeholder="必填:套装价格"/>
                        </div>
                    </div>
                </div>
            </div>
            <!--			</form>-->
        </div>
    </div>
</div>

<div th:include="centre/manage/include::footer"></div>
<script type="text/javascript" src="/js/ueditor/ueditor.config.js"></script>
<script type="text/javascript" src="/js/ueditor/ueditor.all.min.js"></script>
<script type="text/javascript" src="/js/ueditor/lang/zh-cn/zh-cn.js"></script>
<script type="text/javascript" src="/js/ueditor/custom.js?v=2"></script>
<script type="text/javascript" src="/js/appjs/product/AreaData.js"></script>
<script type="text/javascript" src="/public/ace/js/ace-extra.js"></script>
<script type="text/javascript" src="/js/plugins/layui/layui.js"></script>
<script type="text/javascript" src="/js/plugins/layer/layer.js"></script>
<script type="text/javascript" src="/js/bootstrap.min.js"></script>
<script src="/js/jquery-select/jquery.searchableSelect.js"></script>
<script type="text/javascript" src="/js/plugins/layui/layui.js"></script>
<script type="text/javascript">

    var prefix = "/activity/manage";
    var activityPrefix = "/activity/manage";

    $(function () {
        // tab切换
        $('#myTab a').click(function (e) {
            e.preventDefault();
            $('#myTab li').each(function () {
                $(this).removeClass('active')
            })
            $('.tab-content .tab-pane').each(function () {
                $(this).removeClass('active')
            })
            $(this).parent().addClass('active')
            id = $(this).attr('href')
            $(id).addClass('active');
        });
        // packageCouponListTableTableReload();
        joinProductListTableTableReload();
        joinActivityProductListTableTableReload();
        joinActivityProductCouponListTableReload();
    })


    function reLoadCouponList() {
        $('#packageCouponListTable').bootstrapTable('refresh');
    }

    function packageCouponListTableTableReload() {
        $('#packageCouponListTable').bootstrapTable('destroy');
        localTable = $('#packageCouponListTable').bootstrapTable({
            method: 'get', // 服务器数据的请求方式 get or post
            url: prefix + "/listAllProduct", // 服务器数据的加载地址
            showRefresh: true,
            // showToggle : true,
            iconSize: 'outline',
            // toolbar: '#exampleToolbar',
            striped: true, // 设置为true会有隔行变色效果
            dataType: "json", // 服务器返回的数据类型
            pagination: true, // 设置为true会在底部显示分页条
            pageList: [10, 20, 50],
            // queryParamsType : "limit",
            // //设置为limit则会发送符合RESTFull格式的参数
            singleSelect: false, // 设置为true将禁止多选
            // contentType : "application/x-www-form-urlencoded",
            // //发送到服务器的数据编码类型
            pageSize: 10, // 如果设置了分页，每页数据条数
            pageNumber: 1, // 如果设置了分布，首页页码
            // search : true, // 是否显示搜索框
            showColumns: true, // 是否显示内容下拉框（选择显示的列）
            sidePagination: "server", // 设置在哪里进行分页，可选值为"client" 或者
            // "server"
            queryParams: function (params) {
                return {
                    limit: params.limit,
                    offset: params.offset,
                    startDate: $.trim($("#startDate").val()),
                    endDate: $.trim($("#endDate").val()),
                    activityId: $.trim($("#activityId").val()),
                    type: 5
                };
            },
            columns: [
                {
                    field: 'id', // 列字段名
                    title: 'ID' // 列标题
                },
                {
                    field: 'productId',
                    hidden: true,
                    title: '商品ID'
                },
                {
                    field: 'centreId',
                    hidden: true,
                    title: '商户ID'
                },
                {
                    field: 'productName',
                    title: '优惠券标题'
                },
                {
                    field: 'stock',
                    title: '赠送数量',
                    formatter: function (value, row, index) {
                        var title = row.title;
                        var str = '<span class="btn btn-xs btn-warning">' + value + '</span>';
                        return str;
                    }
                },
                {
                    field: 'activityPrice',
                    title: '套餐价格'
                },
                {
                    field: 'vipPrice',
                    title: 'vip价格'
                },
                {
                    title: '操作',
                    field: 'id',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var html = '';
                        //商品未参加活动，才显示参加的逻辑
                        html = html + '<a class="btn btn-primary btn-sm" title="编辑" onclick="editCoupon(\'' + encodeURI(JSON.stringify(row)) + '\')"><i class="fa fa-edit"></i>编辑</a>';
                        html = html + '<a class="btn btn-primary btn-warning" title="移除" onclick="removeActivityProduct(\'' + row.activityProductKey + '\')"><i class="fa fa-edit"></i>移除</a>';

                        return html;
                    }
                }],
            onLoadSuccess: function () {
            },
            onLoadError: function () {
                showTips("数据加载失败！");
            }
        });
    }

    function reLoadProductList() {
        $('#joinProductListTable').bootstrapTable('refresh');
    }

    function reLoadActivityProductList() {
        $('#activityProductTable').bootstrapTable('refresh');
    }

    function reLoadActivityProductCouponList() {
        $('#activityProductCouponTable').bootstrapTable('refresh');
    }

    function joinActivityProductCouponListTableReload() {
        $('#activityProductCouponTable').bootstrapTable('destroy');
        localTable = $('#activityProductCouponTable').bootstrapTable({
            method: 'get', // 服务器数据的请求方式 get or post
            url: prefix + "/selectAll/activityProductCoupon", // 服务器数据的加载地址
            showRefresh: true,
            // showToggle : true,
            iconSize: 'outline',
            // toolbar: '#exampleToolbar',
            striped: true, // 设置为true会有隔行变色效果
            dataType: "json", // 服务器返回的数据类型
            pagination: true, // 设置为true会在底部显示分页条
            pageList: [10, 20, 50],
            // queryParamsType : "limit",
            // //设置为limit则会发送符合RESTFull格式的参数
            singleSelect: false, // 设置为true将禁止多选
            // contentType : "application/x-www-form-urlencoded",
            // //发送到服务器的数据编码类型
            pageSize: 10, // 如果设置了分页，每页数据条数
            pageNumber: 1, // 如果设置了分布，首页页码
            // search : true, // 是否显示搜索框
            showColumns: true, // 是否显示内容下拉框（选择显示的列）
            sidePagination: "server", // 设置在哪里进行分页，可选值为"client" 或者
            // "server"
            queryParams: function (params) {
                return {
                    activityId: $("#activityId").val() ? $.trim($("#activityId").val()) : 0,
                    type: 7
                };
            },
            columns: [
                {
                    field: 'id', // 列字段名
                    title: 'ID' // 列标题
                },
                {
                    field: 'title',
                    title: '优惠券名称'
                },
                {
                    field: 'img',
                    title: '优惠券图片',
                    formatter: function (value, row, index) {
                        return '<img style="width:100px;height:80px" src=' + value + '>';
                    }
                },
                {
                    field: 'teamName',
                    title: '门店名称'
                },
                {
                    field: 'count',
                    title: '参与份数'
                },
                {
                    field: 'bigGiftAmount',
                    title: '核销金额'
                }],
            onLoadSuccess: function () {
            },
            onLoadError: function () {
                showTips("数据加载失败！");
            }
        });
    }


    function joinActivityProductListTableTableReload() {
        $('#activityProductTable').bootstrapTable('destroy');
        localTable = $('#activityProductTable').bootstrapTable({
            method: 'get', // 服务器数据的请求方式 get or post
            url: prefix + "/selectAll/activityProduct", // 服务器数据的加载地址
            showRefresh: true,
            // showToggle : true,
            iconSize: 'outline',
            // toolbar: '#exampleToolbar',
            striped: true, // 设置为true会有隔行变色效果
            dataType: "json", // 服务器返回的数据类型
            pagination: true, // 设置为true会在底部显示分页条
            pageList: [10, 20, 50],
            // queryParamsType : "limit",
            // //设置为limit则会发送符合RESTFull格式的参数
            singleSelect: false, // 设置为true将禁止多选
            // contentType : "application/x-www-form-urlencoded",
            // //发送到服务器的数据编码类型
            pageSize: 10, // 如果设置了分页，每页数据条数
            pageNumber: 1, // 如果设置了分布，首页页码
            // search : true, // 是否显示搜索框
            showColumns: true, // 是否显示内容下拉框（选择显示的列）
            sidePagination: "server", // 设置在哪里进行分页，可选值为"client" 或者
            // "server"
            queryParams: function (params) {
                return {
                    activityId: $("#activityId").val() ? $.trim($("#activityId").val()) : 0,
                    type: 7
                };
            },
            columns: [
                {
                    field: 'id', // 列字段名
                    title: 'ID' // 列标题
                },
                {
                    field: 'title',
                    title: '商品名称'
                },
                {
                    field: 'img',
                    title: '商品图片',
                    formatter: function (value, row, index) {
                        return '<img style="width:100px;height:80px" src=' + value + '>';
                    }
                },
                {
                    field: 'teamName',
                    title: '门店名称'
                },
                {
                    field: 'count',
                    title: '参与份数'
                },
                {
                    field: 'price',
                    title: '价格'
                },
                {
                    field: 'costPrice',
                    title: '成本价'
                }],
            onLoadSuccess: function () {
            },
            onLoadError: function () {
                showTips("数据加载失败！");
            }
        });
    }

    function joinProductListTableTableReload() {
        $('#joinProductListTable').bootstrapTable('destroy');
        localTable = $('#joinProductListTable').bootstrapTable({
            method: 'get', // 服务器数据的请求方式 get or post
            url: prefix + "/listAllProduct", // 服务器数据的加载地址
            showRefresh: true,
            // showToggle : true,
            iconSize: 'outline',
            // toolbar: '#exampleToolbar',
            striped: true, // 设置为true会有隔行变色效果
            dataType: "json", // 服务器返回的数据类型
            pagination: true, // 设置为true会在底部显示分页条
            pageList: [10, 20, 50],
            // queryParamsType : "limit",
            // //设置为limit则会发送符合RESTFull格式的参数
            singleSelect: false, // 设置为true将禁止多选
            // contentType : "application/x-www-form-urlencoded",
            // //发送到服务器的数据编码类型
            pageSize: 10, // 如果设置了分页，每页数据条数
            pageNumber: 1, // 如果设置了分布，首页页码
            // search : true, // 是否显示搜索框
            showColumns: true, // 是否显示内容下拉框（选择显示的列）
            sidePagination: "server", // 设置在哪里进行分页，可选值为"client" 或者
            // "server"
            queryParams: function (params) {
                return {
                    limit: params.limit,
                    offset: params.offset,
                    startDate: $.trim($("#startDate").val()),
                    endDate: $.trim($("#endDate").val()),
                    activityId: $.trim($("#activityId").val()),
                    type: 7
                };
            },
            columns: [
                {
                    field: 'id', // 列字段名
                    title: 'ID' // 列标题
                },
                {
                    field: 'productId',
                    hidden: true,
                    title: '店铺ID'
                },
                {
                    field: 'productName',
                    title: '店铺名称'
                },
                {
                    field: 'activityPrice',
                    title: '套餐价'
                },
                {
                    field: 'vipPrice',
                    title: 'vip价'
                },
                {
                    title: '操作',
                    field: 'id',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var e = '<a class="btn  btn-sm '
                            + '" href="#" mce_href="#" title="删除" onclick="removeActivityProduct(\'' + value + '\')"><i class="fa fa-edit"></i>删除</a>';
                        var d = '<a class="btn  btn-sm '
                            + '" href="#" mce_href="#" title="选择商品" onclick="selectStoreFreecharge(\'' + row.id + '\')"><i class="fa fa-edit"></i>选择商品</a>';
                        var d2 = '<a class="btn  btn-sm '
                            + '" href="#" mce_href="#" title="选择优惠券" onclick="selectStoreFreechargeCoupon(\'' + row.id + '\')"><i class="fa fa-edit"></i>选择优惠券</a>';
                        return e+d+d2;
                    }
                }],
            onLoadSuccess: function () {
            },
            onLoadError: function () {
                showTips("数据加载失败！");
            }
        });
    }

    function closeDow() {
        parent.reLoad();
        var index = parent.layer.getFrameIndex(window.name); // 获取窗口索引
        parent.layer.close(index);
    }

    layui.use('laydate', function () {
        var laydate = layui.laydate;
        laydate.render({
            elem: '#timestart', type: 'datetime'
        });

        laydate.render({
            elem: '#timeend', type: 'datetime'
        });

        laydate.render({
            elem: '#upStartTime', type: 'datetime'
        });

        laydate.render({
            elem: '#upEndTime', type: 'datetime'
        });


    })

    function nextStep() {
        var activityId = $('#activityId').val();
        if (activityId) {
            $('#myTab a[href="#tab_des"]').trigger("click");
        } else {
            layer.alert("请先保存活动信息!", {icon: 5});
        }
    }

    var ue = UE.getEditor('content');
    $('#content').data('editor', ue);
    $('#content').parents('form').submit(function () {
        if (ue.queryCommandState('source')) {
            ue.execCommand('source');
        }
    });

    var ue1 = UE.getEditor('tips');
    $('#tips').data('editor', ue1);
    $('#tips').parents('form').submit(function () {
        if (ue1.queryCommandState('source')) {
            ue1.execCommand('source');
        }
    });

    var ue2 = UE.getEditor('productDescription');
    $('#productDescription').data('editor', ue2);
    $('#productDescription').parents('form').submit(function () {
        if (ue2.queryCommandState('source')) {
            ue2.execCommand('source');
        }
    });

    UE.registerUI('uploadImage', function (editor, uiName) {
        return new UE.ui.Button({
            name: '上传图片',
            title: '上传图片',
            cssRules: 'background-position:-380px 0',
            onclick: function () {
                layer.open({
                    id: 'selectImgs',
                    type: 2,
                    title: '批量选择图片',
                    maxmin: true,
                    shadeClose: false,
                    area: ['60%', '70%'],
                    content: '/platform/config/batchUploadImgUeditor?inputId=' + editor.key  // iframe的url
                });
            }
        });
    });

    // 加载图片进ueditor中
    function loadImgsToUeditor(result, inputId) {
        if (!result || result.length < 1) {
            layer.msg(result.msg, {icon: 7});
            return;
        }
        console.info(result);
        /* var imgUrlArray = result.split(","); */
        let editor = UE.getEditor(inputId);
        for (var i = 0; i < result.length; i++) {
            var imgUrl = result[i];
            editor.execCommand('inserthtml', `<img src=${imgUrl}>`);
        }
    }
    /**
     * 选择优惠券
     */
    function chooseCoupon() {
        // iframe层
        layer.open({
            id: 'group_add',
            type: 2,
            title: '选择优惠券',
            maxmin: true,
            shadeClose: false, // 点击遮罩关闭层
            area: ['90%', '90%'],
            content: prefix + '/toChooseCoupon?activityType=5&activityId=' + $('#activityId').val(),
            cancel: function () {
                //右上角关闭回调
                reLoadCouponList();
                return true; // 开启该代码可禁止点击该按钮关闭
            }
        });
    }

    /**
     * 选择商品
     */
    function chooseJoinProduct() {
        // iframe层
        layer.open({
            id: 'group_add',
            type: 2,
            title: '选择商品',
            maxmin: true,
            shadeClose: false, // 点击遮罩关闭层
            area: ['90%', '90%'],
            content: prefix + '/toChooseJoinProduct?activityType=6&activityId=' + $('#activityId').val(),
            cancel: function () {
                //右上角关闭回调
                reLoadProductList();
                return true; // 开启该代码可禁止点击该按钮关闭
            }
        });
    }

    /**
     * 选择商品
     */
    function chooseShop() {
        // iframe层
        layer.open({
            id: 'group_add',
            type: 2,
            title: '选择门店',
            maxmin: true,
            shadeClose: false, // 点击遮罩关闭层
            area: ['90%', '90%'],
            content: prefix + '/toChooseJoinShop?activityType=6&activityId=' + $('#activityId').val(),
            cancel: function () {
                //右上角关闭回调
                reLoadProductList();
                return true; // 开启该代码可禁止点击该按钮关闭
            }
        });
    }

    /**
     * 选择商家
     */
    function chooseCentre() {

        // iframe层
        layer.open({
            id: 'choose_centre',
            type: 2,
            title: '选择店铺',
            maxmin: true,
            shadeClose: false, // 点击遮罩关闭层
            area: ['70%', '80%'],
            content: "/centre/manage/chooseCentre" // iframe的url
        });
    }

    var row = {};

    function showProductPackagePrice() {
        if (this.row) {
            $("#goodsName").val(this.row.productName);//商品名称
            $("#goodsStock").val(this.row.total);//库存
            $("#packagePrice").val(this.row.activityPrice);//套装价格
            $("#vipPrice").val(this.row.vipPrice);//vip价格
        }
        layer.open({
            type: 1,
            title: false,
            closeBtn: 0,
            area: ['auto'],
            shadeClose: false,
            content: $("#goodsPackageSetting"),
            btn: ['确定', '取消'],
            yes: function (index, layero) {
                //更新选中row的数据
                var rows = $("#joinProductListTable").bootstrapTable('getData');//行的数据
                var rowData = {};
                var dataIndex = -1;
                for (var i = 0; i < rows.length; i++) {
                    if (rows[i].productId == row.productId) {
                        rowData = rows[i];
                        dataIndex = i;
                        break;
                    }
                }

                console.info(row);
                //找到了对应的数据，直接替换
                if (dataIndex != -1) {
                    row.activityPrice = $("#packagePrice").val();
                    $("#joinProductListTable").bootstrapTable("updateRow", {
                        index: dataIndex,//更新行索引，0起始
                        replace: true,//合并or替换行数据，true替换，false合并，默认false
                        row: row
                    });
                }

                layer.close(index);
            },
            cancel: function () {
                //右上角关闭回调
                return true;// 开启该代码可禁止点击该按钮关闭
            }
        });

    }

    function showCouponData() {
        if (this.row) {
            $("#couponName").val(this.row.ticketName);
            $("#couponCount").val(1);
            $("#couponPrice").val('');
        }
        layer.open({
            type: 1,
            title: false,
            closeBtn: 0,
            area: ['auto'],
            shadeClose: false,
            content: $("#couponSetting"),
            btn: ['确定', '取消'],
            yes: function (index, layero) {
                //更新选中row的数据
                var rows = $("#packageCouponListTable").bootstrapTable('getData');//行的数据
                var rowData = {};
                var dataIndex = -1;
                for (var i = 0; i < rows.length; i++) {
                    if (rows[i].productId == row.productId) {
                        rowData = rows[i];
                        dataIndex = i;
                        break;
                    }
                }

                console.info(row);
                //找到了对应的数据，直接替换
                if (dataIndex != -1) {
                    row.stock = $("#couponCount").val();
                    row.activityPrice = $("#couponPrice").val();
                    $("#packageCouponListTable").bootstrapTable("updateRow", {
                        index: dataIndex,//更新行索引，0起始
                        replace: true,//合并or替换行数据，true替换，false合并，默认false
                        row: row
                    });
                }

                layer.close(index);
            }
            , cancel: function () {
                //右上角关闭回调
                return true;// 开启该代码可禁止点击该按钮关闭
            }
        });

    }

    /**
     * 选择sku 设置类型
     */
    var index = 0;

    // function showSeckillPriceStock(id) {
    //
    //     index = layer.open({
    //         type: 2,
    //         title: '选择活动赠品',
    //         closeBtn: 0,
    //         area: ['100%', '100%'],
    //         shadeClose: false,
    //         content: prefix + '/toProductGroupStockSetting?productCentreId=' + id
    //     });
    // }


    /**
     * 选择sku 设置类型
     */
    var giftGoodsIndex = 0;

    function showSelectGiftGoods(productId) {

        giftGoodsIndex = layer.open({
            type: 2,
            title: '选择活动赠品',
            closeBtn: 0,
            area: ['100%', '100%'],
            shadeClose: false,
            content: prefix + '/toGiftProductSpecSelect?productId=' + productId
        });
    }

    function showSelectJoinGoods(productId) {

        giftGoodsIndex = layer.open({
            type: 2,
            title: '选择活动赠品',
            closeBtn: 0,
            area: ['100%', '100%'],
            shadeClose: false,
            content: prefix + '/toJoinProductSpecSelect?productId=' + productId
        });
    }

    function modelIsChecked() {
        if ($("#mode1").is(':checked')) {//套装为商品
            $('#choseGoodsGroup').show();
            $('#choseCouponGroup').hide();

        } else {//套装为优惠券
            $('#choseGoodsGroup').hide();
            $('#choseCouponGroup').show();
        }
    }

    function remove(row) {
        layer.open({
            type: 1,
            title: false,
            closeBtn: 0,
            area: ['auto'],
            shadeClose: false,
            content: '确定删除该赠品？',
            btn: ['确定', '取消'],
            yes: function (index, layero) {

                var rows = $("#packageCouponListTable").bootstrapTable('getData');//行的数据
                var newRows = [];
                var rowData = {};
                var dataIndex = 0;
                for (var i = 0; i < rows.length; i++) {
                    if (rows[i].productId != row.productId) {
                        newRows.push(rows[i]);
                    }
                }

                this.data = newRows;
                reLoadCouponList();

                layer.close(index);
            }
            , cancel: function () {
                //右上角关闭回调
                return true;// 开启该代码可禁止点击该按钮关闭
            }
        });

    }

    function removeCoupon(productId) {
        layer.open({
            type: 1,
            title: false,
            closeBtn: 0,
            area: ['auto'],
            shadeClose: false,
            content: '确定删除该赠品？',
            btn: ['确定', '取消'],
            yes: function (index, layero) {

                var rows = $("#packageCouponListTable").bootstrapTable('getData');//行的数据
                var newRows = [];
                var rowData = {};
                var dataIndex = 0;
                for (var i = 0; i < rows.length; i++) {
                    if (rows[i].productId != productId) {
                        newRows.push(rows[i]);
                    }
                }

                this.data = newRows;
                // packageCouponListTableTableReload();
                reLoadCouponList();

                layer.close(index);
            }
            , cancel: function () {
                //右上角关闭回调
                return true;// 开启该代码可禁止点击该按钮关闭
            }
        });

    }

    function editCoupon(productId, productName, stock, activityPrice) {

        if (row) {
            $("#couponName").val(productName);
            $("#couponCount").val(stock);
            $("#couponPrice").val(activityPrice);
        }
        layer.open({
            type: 1,
            title: false,
            closeBtn: 0,
            area: ['auto'],
            shadeClose: false,
            content: $("#couponSetting"),
            btn: ['确定', '取消'],
            yes: function (index, layero) {
                //更新选中row的数据
                var rows = $("#packageCouponListTable").bootstrapTable('getData');//行的数据
                var rowData = {};
                var dataIndex = -1;
                for (var i = 0; i < rows.length; i++) {
                    if (rows[i].productId == productId) {
                        rowData = rows[i];
                        dataIndex = i;
                        break;
                    }
                }

                console.info(rowData);
                //找到了对应的数据，直接替换
                if (dataIndex != -1) {
                    rowData.stock = $("#couponCount").val();
                    rowData.activityPrice = $("#couponPrice").val();
                    $("#packageCouponListTable").bootstrapTable("updateRow", {
                        index: dataIndex,//更新行索引，0起始
                        replace: true,//合并or替换行数据，true替换，false合并，默认false
                        row: rowData
                    });
                }

                layer.close(index);
            }
            , cancel: function () {
                //右上角关闭回调
                return true;// 开启该代码可禁止点击该按钮关闭
            }
        });

    }

    function callClose() {
        layer.close(index);
        layer.close(giftGoodsIndex);
    }

    $.validator.setDefaults({
        submitHandler: function () {
            saveProduct();
        }
    });

    function validateRule() {
        var icon = "<i class='fa fa-times-circle'></i> ";
        $("#signupForm").validate({
            rules: {
                activityName: {
                    required: true
                },
                startTime: {
                    required: true
                },
                endTime: {
                    required: true
                }
            },
            messages: {
                activityName: {
                    required: icon + "活动名称不能为空"
                },
                startTime: {
                    required: icon + "开始时间不能为空"
                },
                endTime: {
                    required: icon + "结束时间不能为空"
                }
            }
        })
    }

    function saveActivity() {

        var activityName = $("#activityName").val();
        if (!activityName) {

            layer.tips("活动名称不能为空", '#activityName', {time: 2000, tips: 2});

            $("#activityName").focus();
            return;
        }
        var startTime = $("#startTime").val();
        if (!startTime) {
            layer.tips("开始时间不能为空", '#startTime', {time: 2000, tips: 2});

            $("#startTime").focus();
            return;
        }
        var endTime = $("#endTime").val();
        if (!endTime) {
            layer.tips("结束时间不能为空", '#endTime', {time: 2000, tips: 2});
            toastr.error("结束时间不能为空");
            $("#endTime").focus();
            return;
        }
        var thumb = $("#thumb").val();
        if (!thumb) {

            layer.tips("活动图片不能为空", '#thumb', {time: 2000, tips: 2});

            $("#thumb").focus();
            return;
        }
        var listImg = $("#listImg").val();
        var posterImg = $("#posterImg").val();
        var detailsImg = $("#detailsImg").val();
        // var selectTeamId = $("#selectTeamId").val();
        // if (!selectTeamId) {
        //     layer.tips("请选择门店", '#selectTeamId', {time: 2000, tips: 2});
        //     $("#selectTeamId").focus();
        //     return;
        // }

        var rule = $("input[name='rule']:checked").val();
        // var mode = $("input[name='mode']:checked").val();
        var cond = $("#cond").val();

        var joinNum = $("#joinNum").val();
        var range = $("input[name='range']:checked").val();

        var stock = $("#stock").val();
        var sold = $("#sold").val();
        var activityPrice = $("#activityPrice").val();
        var vipPrice = $("#vipPrice").val();
        var productprice = $("#productprice").val();
        var consumptionIntegral = $("#consumptionIntegral").val();
        var plateType = $("input[name='plateType']:checked").val();
        var giftBagCommission1 = $("#giftBagCommission1").val();
        var giftBagCommission2 = $("#giftBagCommission2").val();
        var shareCommission = $("#shareCommission").val();

        var description = UE.getEditor('content').getContent();
        var productDescription = UE.getEditor('productDescription').getContent();
        var tips = UE.getEditor('tips').getContent();

        var activityId = $('#activityId').val();
        var data = {
            id: activityId,
            activityName: activityName,
            startTime: startTime,
            endTime: endTime,
            rule: rule,
            cond: cond,
            joinNum: joinNum,
            range: range,
            type: 6,
            stock: stock,
            sold: sold,
            // mode: mode,
            thumb: thumb,
            listImg: listImg,
            posterImg: posterImg,
            detailsImg: detailsImg,
            description: description,
            productDescription: productDescription,
            tips: tips,
            // teamId: selectTeamId,
            activityPrice: activityPrice,
            vipPrice: vipPrice,
            productprice: productprice,
            consumptionIntegral: consumptionIntegral,
            plateType: plateType,
            giftBagCommission1: giftBagCommission1,
            giftBagCommission2: giftBagCommission2,
            shareCommission: shareCommission
        }

        $.ajax({
            url: '/activity/manage/saveActivity',
            contentType: "application/json",
            dataType: "json",
            type: 'POST',
            data: JSON.stringify(data),
            success: function (result) {
                if (result.code == 0) {
                    if (result.data && !activityId) {
                        $('#activityId').val(result.data);
                    }
                    layer.alert("保存成功", {icon: 6});
                    nextStep();
                } else {
                    if (result.msg != "" && result.msg != null) {
                        layer.alert(result.msg, {icon: 5});
                    } else {
                        layer.alert("保存失败，请联系管理员", {icon: 5});
                    }

                }
            }
        })
    }

    function saveProduct() {
        var sku = localStorage.getItem("productSKU");

        var activityName = $("#activityName").val();
        if (!activityName) {

            layer.tips("活动名称不能为空", '#activityName', {time: 2000, tips: 2});

            $("#activityName").focus();
            return;
        }
        var startTime = $("#startTime").val();
        if (!startTime) {
            layer.tips("开始时间不能为空", '#startTime', {time: 2000, tips: 2});

            $("#startTime").focus();
            return;
        }
        var endTime = $("#endTime").val();
        if (!endTime) {
            layer.tips("结束时间不能为空", '#endTime', {time: 2000, tips: 2});
            toastr.error("结束时间不能为空");
            $("#endTime").focus();
            return;
        }

        var rule = $("input[name='rule']:checked").val();
        var mode = $("input[name='mode']:checked").val();
        var cond = $("#cond").val();

        //赠品商品列表
        var giftProductList = $("#packageCouponListTable").bootstrapTable('getData');//行的数据
        var giftProductSkuList = localStorage.getItem("productSKU");

        var joinNum = $("#joinNum").val();
        var range = $("input[name='range']:checked").val();
        var joinProductList = $("#joinProductListTable").bootstrapTable('getData');//行的数据
        var joinProductSkuList = localStorage.getItem("joinProductSKU");


        // var centreId = this.row.centreId;
        // var teamId = this.row.liansuoid;

        // var productName = this.row.title;
        // var thumb = this.row.thumb;
        //
        // var groupPrice = $("#groupPrice").val();
        var stock = $("#stock").val();
        var sold = $("#sold").val();
        // var needJoinGroupNum = $("#needJoinGroupNum").val();

        var centerId = '';
        var teamId = '';
        var data = {
            centreId: centerId,
            teamId: teamId,
            activityName: activityName,
            startTime: startTime,
            endTime: endTime,
            rule: rule,
            mode: mode,
            cond: cond,
            giftProductList: giftProductList,
            giftProductSkuList: giftProductSkuList,
            joinNum: joinNum,
            range: range,
            joinProductList: joinProductList,
            joinProductSkuList: joinProductSkuList,
            type: 5,
            stock: stock,
            sold: sold
        }

        var giftProductArray = [];
        if (giftProductList) {
            // var giftProductListJson = JSON.parse(giftProductList);
            for (var i = 0; i < giftProductList.length; i++) {
                var tempProduct = giftProductList[i];
                if (centerId == '' || !centerId) {
                    centerId = tempProduct.centreId;
                }
                if (teamId == '' || !teamId) {
                    teamId = tempProduct.teamId;
                }
                // var product = {
                //     productId: tempProduct.id,
                //     productName: tempProduct.title
                // }
                giftProductArray.push(tempProduct);
            }
        }
        data.giftProductList = giftProductArray;

        var giftProductSkuArray = [];
        if (giftProductSkuList) {
            var giftProductSkuListJson = JSON.parse(giftProductSkuList);
            for (var i = 0; i < giftProductSkuListJson.length; i++) {
                var tempSku = giftProductSkuListJson[i];
                if (centerId == '' || !centerId) {
                    centerId = tempSku.centreId;
                }
                if (teamId == '' || !teamId) {
                    teamId = tempSku.teamId;
                }
                var sku = {
                    id: tempSku.id,
                    productCentreId: tempSku.productCentreId,
                    centreId: tempSku.centreId,
                    teamId: tempSku.teamId,
                    skuId: tempSku.id,
                    title: tempSku.title,
                    thumb: tempSku.thumb,
                    groupPrice: tempSku.groupPrice,
                    specs: tempSku.specs,
                    stock: tempSku.stock,
                    giftAmount: tempSku.giftAmount,
                    giftAllAmount: tempSku.giftAllAmount
                }
                giftProductSkuArray.push(tempSku);
            }
        }
        data.giftProductSkuList = giftProductSkuArray;

        var activityPrice = 0;
        var joinProductArray = [];
        if (joinProductList) {
            // var joinProductListJson = JSON.parse(joinProductList);
            for (var i = 0; i < joinProductList.length; i++) {
                var tempProduct = joinProductList[i];
                if (centerId == '' || !centerId) {
                    centerId = tempProduct.centreId;
                }
                if (teamId == '' || !teamId) {
                    teamId = tempProduct.teamId;
                }

                //商品套装，则需要计算套装价格
                if (mode == 1) {
                    activityPrice += tempProduct.activityPrice ? tempProduct.activityPrice : 0;
                }
                // var product = {
                //     productId: tempProduct.id,
                //     productName: tempProduct.title
                // }
                joinProductArray.push(tempProduct);
            }
        }
        data.joinProductList = joinProductArray;
        data.activityPrice = activityPrice;

        var joinProductSkuArray = [];
        if (joinProductSkuList) {
            var joinProductSkuListJson = JSON.parse(joinProductSkuList);
            for (var i = 0; i < joinProductSkuListJson.length; i++) {
                var tempSku = joinProductSkuListJson[i];
                if (centerId == '' || !centerId) {
                    centerId = tempSku.centreId;
                }
                if (teamId == '' || !teamId) {
                    teamId = tempSku.teamId;
                }
                var sku = {
                    id: tempSku.id,
                    productCentreId: tempSku.productCentreId,
                    centreId: tempSku.centreId,
                    teamId: tempSku.teamId,
                    skuId: tempSku.id,
                    title: tempSku.title,
                    thumb: tempSku.thumb,
                    groupPrice: tempSku.groupPrice,
                    specs: tempSku.specs,
                    stock: tempSku.stock,
                    giftAmount: tempSku.giftAmount,
                    giftAllAmount: tempSku.giftAllAmount
                }
                joinProductSkuArray.push(tempSku);
            }
        }
        data.joinProductSkuList = joinProductSkuArray;
        data.centreId = centerId;
        data.teamId = teamId;

        if (mode == 1) {//优惠套装-商品打包
            data.giftProductList = [];
            data.giftProductSkuList = [];
        } else {//优惠套装-优惠券打包
            data.joinProductList = [];
            data.joinProductSkuList = [];
        }

        $.ajax({
            url: '/activity/manage/saveActivity',
            contentType: "application/json",
            dataType: "json",
            type: 'POST',
            data: JSON.stringify(data),
            success: function (result) {
                if (result.code == 0) {
                    layer.alert("保存成功", {icon: 6});
                } else {
                    if (result.msg != "" && result.msg != null) {
                        layer.alert(result.msg, {icon: 5});
                    } else {
                        layer.alert("保存失败，请联系管理员", {icon: 5});
                    }

                }
            }
        })
    }

    function removeActivityProduct(activityProductKey) {

        layer.open({
            type: 1,
            title: false,
            closeBtn: 0,
            area: ['auto'],
            shadeClose: false,
            content: '所选中的商品移除后，将不再参加此套装？',
            btn: ['确定', '取消'],
            yes: function (index, layero) {
                $.ajax({
                    url: '/activity/manage/removeActivityProduct',
                    type: "post",
                    data: {
                        'id': activityProductKey
                    },
                    success: function (r) {
                        if (r.code == 0) {
                            layer.alert("处理成功", {icon: 6});
                            //刷新
                            reLoadProductList();
                            reLoadActivityProductList();
                            reLoadActivityProductCouponList();
                        } else {
                            layer.msg(r.msg);
                        }
                    }
                });
                // })

                layer.close(index);
            }
            , cancel: function () {
                //右上角关闭回调
                return true;// 开启该代码可禁止点击该按钮关闭
            }
        });
    }

    /**
     * 优惠券编辑
     * @param rowEncode
     */
    function editCoupon(rowEncode) {

        var decodeRow = decodeURI(rowEncode);
        var row = JSON.parse(decodeRow);

        showPackageCouponPrice(row);
    }

    /**
     * 没有多规格的商品编辑
     */
    function showPackageCouponPrice(productRow) {
        if (productRow) {
            $("#couponName").val(productRow.productName);
            $("#couponCount").val(productRow.stock);
            $("#couponPrice").val(productRow.activityPrice);
        }
        layer.open({
            type: 1,
            title: false,
            closeBtn: 0,
            area: ['auto'],
            shadeClose: false,
            content: $("#couponSetting"),
            btn: ['确定', '取消'],
            yes: function (index, layero) {
                var activityPrice = $("#couponPrice").val();
                if (!activityPrice) {
                    layer.alert("请输入套装价格", {icon: 5});
                    return;
                }
                var couponCount = $("#couponCount").val();
                if (!couponCount) {
                    layer.alert("请输入套装优惠券数量", {icon: 5});
                    return;
                }
                $.ajax({
                    url: '/activity/manage/editActivityProduct',
                    contentType: "application/json",
                    dataType: "json",
                    type: 'POST',
                    data: JSON.stringify({
                        id: productRow.id,
                        stock: $("#couponCount").val(),
                        activityPrice: $("#couponPrice").val()
                    }),
                    success: function (result) {
                        if (result.code == 0) {
                            layer.alert("处理成功", {icon: 6});
                            //刷新
                            reLoadCouponList();
                        } else {
                            if (result.msg != "" && result.msg != null) {
                                layer.alert(result.msg, {icon: 5});
                            } else {
                                layer.alert("处理失败，请联系管理员", {icon: 5});
                            }
                        }
                    }
                });

                layer.close(index);
            }
            , cancel: function () {
                //右上角关闭回调
                return true;// 开启该代码可禁止点击该按钮关闭
            }
        });

    }

    function selectStoreFreecharge(id) {
        layer.open({
            id : 'selectStoreFreecharge',
            type : 2,
            title : '选择门店商品',
            maxmin : true,
            shadeClose : false, // 点击遮罩关闭层
            area : [ '90%', '90%' ],
            content : '/activity/manage/selectStoreFreecharge?id='+id // iframe的url
        });
    }

    /**
     * 添加活动产品
     * @param rowEncode
     */
    function editProduct(rowEncode) {

        var decodeRow = decodeURI(rowEncode);
        var row = JSON.parse(decodeRow);
        //有多规格的
        if (row.hasoption == 1) {
            showSeckillPriceStock(row.productId);
        }
        //没有多规格的
        else {
            showPackageProductPrice(row);
        }

        //parent.chooseProductCallback(row, $('#isJoinProduct').val());
        //var index = parent.layer.getFrameIndex(window.name); // 获取窗口索引
        //parent.layer.close(index);
    }

    /**
     * 选择sku 设置类型
     */
    var index = 0;

    function showSeckillPriceStock(id) {
        index = layer.open({
            type: 2,
            title: '选择商品规格',
            closeBtn: 0,
            area: ['100%', '100%'],
            shadeClose: false,
            content: activityPrefix + '/toProductSpecSelect?productId=' + id + '&activityId=' + $('#activityId').val()
        });
    }

    /**
     * 没有多规格的商品编辑
     */
    function showPackageProductPrice(productRow) {
        if (productRow) {
            $("#goodsName").val(productRow.productName);//商品名称
            $("#goodsStock").val(productRow.stock);//库存
            $("#packagePrice").val(productRow.activityPrice);//套装价格
        }
        layer.open({
            type: 1,
            title: false,
            closeBtn: 0,
            area: ['auto'],
            shadeClose: false,
            content: $("#goodsPackageSetting"),
            btn: ['确定', '取消'],
            yes: function (index, layero) {
                var activityPrice = $("#packagePrice").val();
                if (!activityPrice) {
                    layer.alert("请输入套装价格", {icon: 5});
                    return;
                }
                $.ajax({
                    url: '/activity/manage/editActivityProduct',
                    contentType: "application/json",
                    dataType: "json",
                    type: 'POST',
                    data: JSON.stringify({
                        id: productRow.id,
                        activityId: productRow.activityId,
                        activityPrice: $("#packagePrice").val()
                    }),
                    success: function (result) {
                        if (result.code == 0) {
                            layer.alert("处理成功", {icon: 6});
                            //刷新
                            reLoadProductList();
                        } else {
                            if (result.msg != "" && result.msg != null) {
                                layer.alert(result.msg, {icon: 5});
                            } else {
                                layer.alert("处理失败，请联系管理员", {icon: 5});
                            }
                        }
                    }
                });

                layer.close(index);
            }
            , cancel: function () {
                //右上角关闭回调
                return true;// 开启该代码可禁止点击该按钮关闭
            }
        });

    }

    function onSelectImgBtnClick(inputId, imgId) {
        layer.open({
            id: 'selectImg',
            type: 2,
            title: '选择图片',
            maxmin: true,
            shadeClose: false,
            area: ['60%', '70%'],
            content: '/platform/config/selectImg/' + inputId + "/" + imgId // iframe的url
        });
    }

    // 批量上传图片
    function selectImgs(domId) {
        layer.open({
            id: 'selectImgs',
            type: 2,
            title: '批量选择图片',
            maxmin: true,
            shadeClose: false,
            area: ['60%', '70%'],
            content: '/platform/config/batchUploadImg/' + domId // iframe的url
        });
    }

    function loadImgsInfo(domId, result) {
        if (!result || result.length < 1) {
            layer.msg(result.msg, {icon: 7});
            return;
        }
        $('#detailsImg').val(result.join(","));
    }

    /**
     * 加载图片URL
     * @param inputId
     * @param imgId
     * @param url
     */
    function loadImgUrl(inputId, imgId, url) {
        $('#' + inputId + '').val(url);
        $('#' + imgId + '').attr('src', url);
    }

    function selectStoreFreechargeCoupon(id) {
       let activityPrice = $("#activityPrice").val();
        let vipPrice = $("#vipPrice").val();
        layer.open({
            id : 'selectStoreFreechargeCoupon',
            type : 2,
            title : '选择门店优惠券',
            maxmin : true,
            shadeClose : false, // 点击遮罩关闭层
            area : [ '90%', '90%' ],
            content : '/activity/manage/selectStoreFreechargeCoupon?id='+id+"&activityPrice="+activityPrice+"&vipPrice="+vipPrice // iframe的url
        });
    }
    function commissionNumUpdate(commissionId) {
        let ratio = parseFloat($("#"+commissionId).val())/100;

        let activityPrice = parseFloat($('#activityPrice').val())*ratio;
        let vipPrice = parseFloat($('#vipPrice').val())*ratio;

        $('#'+commissionId+"Num").html("活动价格分佣:"+activityPrice.toFixed(2)+"vip价格分佣:"+vipPrice.toFixed(2));
    }
    $(document).ready(function () {
        commissionNumUpdate("giftBagCommission1");
        commissionNumUpdate("giftBagCommission2");
        $('#giftBagCommission1,#giftBagCommission2').bind('input propertychange', function() {
            let id = $(this).attr("id");
            commissionNumUpdate(id);
        });
    })
</script>

</body>
</html>
